package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

const TOKEN = "token"

func AuthMiddleware() gin.HandlerFunc {
	//return func(c *gin.Context) {
	//	if _, err := token.ParseRequest(c); err != nil {
	//		handler.SendResponse(c, errno.ErrTokenInvalid, nil)
	//		c.Abort()
	//		return
	//	}
	//	c.Next()
	//}

	// 未登录跳转登录页
	return func(c *gin.Context) {
		cookie, err := c.Cookie(TOKEN)
		if err != nil || cookie == "" {
			c.Redirect(http.StatusMovedPermanently, "/login")
			c.Abort()
			return
		}
		c.Next()
	}
}
